﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PureStretch.Web.Templates.Contact
{
    public partial class _default : Acms.AcmsControls.TemplatePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            btnSubmit.Click += new EventHandler(btnSubmit_Click);

        }

        void btnSubmit_Click(object sender, EventArgs e)
        {
            Validate();
            if (IsValid)
            {

                //create the mail message
                System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();

                //set the addresses
                mail.To.Add(new System.Net.Mail.MailAddress("purestretch@live.co.uk", "PureStretch"));
                //mail.To.Add(new System.Net.Mail.MailAddress("t.armfelt@gmail.com", "PureStretch"));
                mail.Bcc.Add("acmspurestretch@gmail.com");
                //mail.To.Add(new System.Net.Mail.MailAddress("toma57@hotmail.com", "Moo Me"));

                mail.From = new System.Net.Mail.MailAddress(txtEmail.Text, txtName.Text);
                //mail.To.Add("you@yourcompany.com");

                //set the content
                mail.Subject = "Email from Pure Stretch site";
                mail.Body = string.Concat("From: ",txtName.Text,"\n Email: ", txtEmail.Text, "\n Message: ",txtMessage.Text);
                /*if (tx.Text != "")
                {
                    //var phone = string.Concat("Phone Number:", txtPhone.Text, "--");
                    mail.Body = string.Concat("Phone Number: ", txtPhone.Text, " -- ", txtQuestion.Text);
                }
                else
                {
                    mail.Body = string.Concat("No Phone Number Provided. ", txtQuestion.Text);
                }*/

                try
                {
                    System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
                    client.Send(mail);
                    mail.Dispose();
                    pnlMessageSent.Visible = true;
                    pnlCreateMsg.Visible = false;
                }
                catch
                {
                    pnlCreateMsg.Visible = false;
                    pnlMessageError.Visible = true;

                }
            }
        }
    }
}
